#ifndef net_hpp
#define net_hpp

class log_c{};
class exception_c{};
#ifdef _win32
typedef unsigned threadfunc_t;
typedef void * threadparam_t;
#define STDPREFIX __stdcall
#elif _linux
typedef void * threadfunc_t;
typedef void * threadparam_t;
#define STDPREFIX
#endif
class lock_c{};
class mutex_c{];
class semaphore_c{};
class condition_c();
class thread_c{
public:
	thread_c();
	virtual ~thread_c();

private:
	static threadfunc_t STDPREFIX exec(threadparam_t);
	bool is_running();
	bool is_release();

protected:
	virtual void run() = 0;

public:
	void sig_running(bool n_sig);
	void sig_release(bool n_sig);

private:
	bool m_running;
	bool m_release;
private:
	thread_c(const thread_c& ) {}
	thread_c& operator=(const thread_c& ) { return *this; }
#ifdef _win32
	HANDLE m_thread;
	unsigned m_dwThreadId;
#elif _linux
	pthread_t m_thread;
#endif
};
class thread_manager_c{
	
};
class stream_c{};
void return_socket_addr(struct sockaddr_in& n_sock_addr, const string& n_host, int n_value);
class sock_c{
protected:
	int m_domain;
    int m_type;
    int m_protocol;

    bool m_active;
    int m_handle;
    bool m_block_mode;

private:
    void enable_block_mode(int n_handle, bool n_value);

protected:
	void sig_active(bool n_value);
    void sig_domain(int n_value);
    void sig_type(int n_value);
    void sig_protocol(int n_value);

public:
    sock_c();
    virtual ~sock_c();

    virtual void open();
    virtual void close();

    bool is_active() { return m_active; }
    int return_handle() { return m_handle; }
    bool is_block_mode() { return m_block_mode; }
    void set_block_mode(bool n_value);
    void set_handle(int n_value);
};
class tcp_sock_c : public sock_c{
public:
    tcp_sock_c() {
        m_type = SOCK_STREAM;
        m_protocol = IPPROTO_TCP;
        m_block_mode = false;
    }
};
class crypto_tcp_sock_c : public tcp_sock_c{
protected:
	SSL_CTX * m_ctx;
	SSL * m_ssl;
public:
	crypto_tcp_sock_c();
	virtual ~crypto_tcp_sock_c();
private:
	void crypto_init();
protected:
	void load_private_cert();
	void load_private_key();
};
class server_crypto_tcp_sock_c : public crypto_tcp_sock_c{
public:
	crypto_tcp_sock_c();
	virtual ~crypto_tcp_sock_c();
};

class client_crypto_tcp_sock_c : public crypto_tcp_sock_c{
public:
	client_crypto_stream_sock_c();
	virtual ~client_crypto_stream_sock_c();
protected:
	void load_ca_cert();
};
class handle_c{
private:
public:
};
class sock_handle_c{
private:
public:
};
class tcp_sock_handle_c : public sock_handle_c{
private:
public:
};
class crypto_tcp_sock_handle_c : public base_stream_sock_handle_c{
private:
public:
};
#endif
